import 'package:flutter/material.dart';
import 'package:flutter2/colors.dart';
import 'package:flutter2/http/api.dart';
import 'package:flutter2/ui/about.dart';
import 'package:flutter2/ui/card_list.dart';
import 'package:flutter2/ui/setting.dart';
import 'package:flutter2/ui/web.dart';
import 'package:flutter2/utils/string.dart';
import 'package:flutter2/utils/user.dart';
import 'package:flutter2/widget/base/base_container.dart';
import 'package:flutter2/widget/base/normal_text.dart';
import 'package:get/get.dart';

class MePage extends StatefulWidget {
  const MePage({super.key});

  @override
  State<MePage> createState() => _MePageState();
}

class _MePageState extends State<MePage> with AutomaticKeepAliveClientMixin {
  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Container(
      decoration: BoxDecoration(
        image: DecorationImage(
          fit: BoxFit.fill,
          image: AssetImage(
            "bg_main".toImage(),
          ),
        ),
      ),
      child: SafeArea(
        child: SingleChildScrollView(
          child: Column(
            children: [
              BaseContainer(
                width: double.infinity,
                padding: EdgeInsets.all(32),
                background: Colors.white,
                radius: 10,
                margin: EdgeInsets.symmetric(horizontal: 16),
                child: Column(
                  children: [
                    BaseContainer(
                      backgroundImg: "ic_head".toImage(),
                      width: 90,
                      height: 90,
                    ),
                    SizedBox(
                      height: 10,
                    ),
                    NormalText(
                      text: "Bienvenido!",
                      fontColor: mainText2,
                      fontSize: 14,
                      fontWeight: FontWeight.bold,
                    ),
                    SizedBox(
                      height: 10,
                    ),
                    NormalText(
                      text: UserUtil.getUser().phone,
                      fontSize: 12,
                      fontColor: mainText2,
                    )
                  ],
                ),
              ),
              SizedBox(height: 20),
              Container(
                height: null,
                color: Colors.white,
                padding: EdgeInsets.symmetric(horizontal: 16),
                margin: EdgeInsets.symmetric(horizontal: 16),
                width: double.infinity,
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    _buildItem(
                      icon: "ic_private",
                      text: "隐私协议",
                      click: () {
                        Get.to(WebPage(
                          url: HttpApi.private,
                          title: "隐私协议",
                        ));
                      },
                    ),
                    _buildItem(
                      icon: "ic_card",
                      text: "银行卡",
                      click: () {
                        Get.to(CardPage());
                      },
                    ),
                    _buildItem(
                      icon: "ic_about",
                      text: "关于",
                      click: () {
                        Get.to(AboutPage());
                      },
                    ),
                    _buildItem(
                      icon: "ic_setting",
                      text: "设置",
                      click: () {
                        Get.to(SettingPage());
                      },
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildItem({
    required String icon,
    required String text,
    GestureTapCallback? click,
  }) {
    return GestureDetector(
      behavior: HitTestBehavior.translucent,
      onTap: click,
      child: Padding(
        padding: const EdgeInsets.symmetric(vertical: 15),
        child: Row(
          children: [
            BaseContainer(
              backgroundImg: icon.toImage(),
              width: 20,
              height: 20,
            ),
            SizedBox(width: 10),
            Expanded(
                child: NormalText(
              text: text,
              fontSize: 14,
              fontColor: mainText2,
            ))
          ],
        ),
      ),
    );
  }

  @override
  bool get wantKeepAlive => true;
}
